package com.bdqn.t330.ch02.repository;

import com.bdqn.t330.ch02.entity.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

//JpaRepository 接口,自己已经实现了一些常用crud方法

@Repository
public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {

    public List<User> findByUsrName(String usrName);

    //自定义ql语句nativeQuery=false 对应的是实体类
//    @Query(value = "select u from User u where u.usrRoleId=?1", nativeQuery = false)
//    public List<User> findByRoleId(Long roleId);

    //自定义ql语句nativeQuery=true 对应的是具体的数据库表
    @Query(value = "select * from sys_user u where u.usr_role_id=?1", nativeQuery = true)
    public List<User> findByUserByRoleId(Long roleId);

//    @Query("select u from User u where u.usrRoleId=?1")
//    public Page<User> findPageByUsrRoleId(Long roleId, Pageable pageable);
}
